home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 99 < prev   
Text File  |  1996-08-06  |  1KB  |  48 lines

  1. Path: news.rmii.com!usenet
  2. From: jcoffin@rmii.com (Jerry Coffin)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Help, best way to compare doubles
  5. Date: Sat, 13 Jan 1996 21:54:41 GMT
  6. Organization: TAEUS
  7. Message-ID: <4d95mp$c01@natasha.rmii.com>
  8. References: <4d1k09$aqq@mercury.IntNet.net>
  9. NNTP-Posting-Host: slip8166.rmii.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. jtomich@IntNet.net (Jeff Tomich) wrote:
  13.  
  14. >Having a hard time to figure out a function on how to compare doubles. 
  15. >Any ideas?
  16.  
  17. Generally something like:
  18. #include <float.h>
  19.  
  20.     double a, b;
  21.     /* ... */
  22.  
  23.     if ( fabs(a-b) <= DBL_EPSILON) {
  24.         /* They're equal */
  25.     }
  26.     else {
  27.         /* They're not equal... */
  28.     }
  29.  
  30. Note that this isn't the real purpose of DBL_EPSILON, so you may need to
  31. change the exact value used...
  32.  
  33. As you've doubtless already dicovered, a simple test for equality or
  34. lack of it is generally meaningless with floating point numbers.
  35.  
  36. BTW, you might want to ask questions like this in comp.lang.c or
  37. comp.lang.c.moderated -- this newsgroup is really intended for
  38. discussion of the C standard, not normal C programming as such.
  39.     Later,
  40.     Jerry.
  41.  
  42. /* I can barely express my own opinions; I certainly can't
  43.  * express anybody else's.
  44.  *
  45.  * The universe is a figment of its own imagination.
  46.  */
  47.  
  48.